package com.zegome.game.gomestory.main.scene.play.board;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.zegome.game.action.IAction;
import com.zegome.game.action.IAction.IActionListener;
import com.zegome.game.action.interpolation.SineOutFunction;
import com.zegome.game.entity.IEntity;
import com.zegome.game.entity.action.AlphaAction;
import com.zegome.game.entity.sprite.BaseSprite;
import com.zegome.game.gomestory.main.scene.BaseGameScreen;

public class Combo extends BaseSprite{
	
	float xScore;
	Board board;
	
	public Combo(Board board, final BaseGameScreen screen, int type,int score, float pX, float pY) {
		
		super(pX, pY);
		this.board = board;
		mX = mX - (179/2);
		mY = mY - (142);
		// TODO Auto-generated constructor stub
		this.type = type;
		this.score = score;
		Label temp = board.screen.ctr.stageHelper.createLabel(board.screen.ctr.g.mFontCombo, "", Color.WHITE, 0, 0);
		temp.setText("+"+score);
		xScore = (179-temp.getWidth())/2;
		alpha = new AlphaAction(2f, 1f, 0f, SineOutFunction.getInstance());
		alpha.addActionListener(new IActionListener<IEntity>() {
			
			@Override
			public void onActionStarted(IAction<IEntity> action, IEntity item) {
				// TODO Auto-generated method stub				
			}
			
			@Override
			public void onActionFinished(IAction<IEntity> action, IEntity item) {
				// TODO Auto-generated method stub					
				screen.postRunnable(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						screen.removeChild(Combo.this);
					}
				});
			}
		});
		this.registerAction(alpha);
	}
	int score;
	int type;
	// 1: kha
	// 2: tot
	// 3: tuyet voi
	AlphaAction alpha;
	public void onUpdate(float pDeltaTime){
		super.onUpdate(pDeltaTime);
		mY+=2*pDeltaTime/0.01f;		
	}
	public void onDraw(final SpriteBatch pSpriteBatch, final float pAlpha) {		
		if (!isVisible)
			return;		
		pSpriteBatch.setColor(mColor.r, mColor.g, mColor.b, mColor.a * pAlpha);				
		if (mScaleX == 1 && mScaleY == 1 && mRotation == 0){				
			if(type>=1)
			pSpriteBatch.draw(board.screen.ctr.a.bgCombo, mX, mY, (179), (142));			
			if(type == 1)
				pSpriteBatch.draw(board.screen.ctr.a.kha, mX+(179-board.screen.ctr.a.kha.getRegionWidth())/2, mY+(142-board.screen.ctr.a.kha.getRegionHeight())/2, board.screen.ctr.a.kha.getRegionWidth(), board.screen.ctr.a.kha.getRegionHeight());			
			else if(type == 2)
				pSpriteBatch.draw(board.screen.ctr.a.tot, mX+(179-board.screen.ctr.a.tot.getRegionWidth())/2, mY+(142-board.screen.ctr.a.tot.getRegionHeight())/2, board.screen.ctr.a.tot.getRegionWidth(), board.screen.ctr.a.tot.getRegionHeight());			
			else if(type == 3)
				pSpriteBatch.draw(board.screen.ctr.a.tuyetvoi,mX+(179-board.screen.ctr.a.tuyetvoi.getRegionWidth())/2, mY+(142-board.screen.ctr.a.tuyetvoi.getRegionHeight())/2, board.screen.ctr.a.tuyetvoi.getRegionWidth(), board.screen.ctr.a.tuyetvoi.getRegionHeight());							
			else if(type>=4){
				pSpriteBatch.draw(board.screen.ctr.a.hoanhao,mX+(179-board.screen.ctr.a.hoanhao.getRegionWidth())/2, mY+(142-board.screen.ctr.a.hoanhao.getRegionHeight())/2, board.screen.ctr.a.hoanhao.getRegionWidth(), board.screen.ctr.a.hoanhao.getRegionHeight());			
			}
			board.screen.ctr.g.mFontCombo.setColor(1f, 1f, 1f, mColor.a * pAlpha);
			board.screen.ctr.g.mFontCombo.draw(pSpriteBatch, "+"+score, mX+xScore, mY);
		}
	}
}
